package com.kitchen.ui.controls.friends
{
	import flash.display.BitmapData;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.MouseEvent;

	internal class ScrollBox extends Sprite
	{
		private var itemBox:Sprite;
		private var pages:Array;
		private var mainSkin:BitmapData;
		
		public function ScrollBox(bitdata:BitmapData)
		{
			super();
			this.mainSkin = bitdata;
			this.pages = new Array();
			this.itemBox = new Sprite();
			var shape:Shape = new Shape();
			shape.graphics.beginFill(0xffffff, 1);
			shape.graphics.drawRect(0, 0, 160, 270);
			this.addChild(shape);
			this.mask = shape;
			this.addChild(this.itemBox);
		}
		
		public function addPage(page:int, friends:Array):void{
			if((page > 0) && (this.pages[page] == null)){
				var pageItems:Array = new Array();
				for each(var itemObj:Object in friends){
					var item:ListItem = new ListItem(this.mainSkin, itemObj);
					item.x = 0;
					item.y = (int(itemObj.odnum)-1)*45;
					item.addEventListener(MouseEvent.CLICK, clickHandle);
					pageItems.push(item);
					this.itemBox.addChild(item);
				}
				this.pages[page] = pageItems;
			}
		}
		
		public function scroll(ps:int):void{
			this.itemBox.y = -(ps*45);
		}
		
		public function removePage(page:int):void{
			if(this.pages[page] != null){
				for each(var item:ListItem in this.pages[page]){
					this.itemBox.removeChild(item);
				}
				this.pages[page] = null;
			}
		}
		
		private function clickHandle(ke:MouseEvent):void{
			trace(ke.target.name);
			this.dispatchEvent(ke);
		}
		
	}
}